package github.fafaovo.common.commands;

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import github.fafaovo.deepcapacity;
import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TranslationTextComponent;


//处理commmands 中玩家死亡数组消失的问题 ExamplePowerEvent
public class SavePostionCommand {
    public SavePostionCommand(CommandDispatcher<CommandSource> dispatcher)
    {
        dispatcher.register(Commands.literal(deepcapacity.MOD_ID).then(Commands.literal("save").executes(
                (c)->{
                    return savePos(c.getSource());
                }
        )));
    }
    private int savePos(CommandSource source) throws CommandSyntaxException
    {
        ServerPlayerEntity player = source.asPlayer();
        BlockPos position = player.getPosition();


        //把坐标存起来
        player.getPersistentData().putIntArray(
                deepcapacity.MOD_ID + ".save_pos",
                new int[]{position.getX(),position.getY(),position.getZ()});


        String pos = position.getX() + "." + position.getY() + "." + position.getZ();
        //source.sendFeedback(new TranslationTextComponent(deepcapacity.MOD_ID + ".save_pos" ,pos),true);

        return 1;
    }
}
